package bo;

import IBO.IForme;
import boerrors.FormeInexistantException;
import dao.AbstractFactory;
import dao.dto.FormeDto;
import java.io.Serializable;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import java.util.Vector;
import util.Util;

public class Forme implements IForme, Serializable{
        private int _idForme;
        private String _libelleForme;
        
	//*******************************************************************
	//Constructeurs
	//*******************************************************************

        public Forme(FormeDto formeDto) throws RemoteException{
                this._idForme = formeDto.getIdForme();
                this._libelleForme = formeDto.getLibelleForme();
                UnicastRemoteObject.exportObject(this,0);
        }
        
        public Forme(int idForme, String libelleForme) throws RemoteException {
		setIdForme(idForme);		
                setLibelleForme(libelleForme);
                UnicastRemoteObject.exportObject(this,0);
        }

        //Convertir bo - dto
        public FormeDto creerFormeDto() throws RemoteException {
                return new FormeDto(this.getIdForme(), this.getLibelleForme());
        }
        
	//*******************************************************************
	//Setters
	//*******************************************************************
        
        public synchronized void setIdForme(int idForme) {
		Util.checkPositive(idForme);
                this._idForme = idForme;
	}
	
        public synchronized void setLibelleForme(String libelleForme) {
		Util.checkString(libelleForme);
                this._libelleForme = libelleForme;
	}
        
	//*******************************************************************
	//Getters
	//*******************************************************************
	public synchronized int getIdForme() throws RemoteException {
		return _idForme;
	}
	
        public synchronized String getLibelleForme() throws RemoteException {
		return _libelleForme;
	}

        //*******************************************************************
	//Methodes
	//*******************************************************************        
        
        @Override
        public String toString(){
                return this._libelleForme;
        }
        
        //*******************************************************************
	//Methodes static
	//*******************************************************************
       
        public synchronized static Vector<Forme> lister() throws RemoteException, FormeInexistantException {
                Vector<FormeDto> listeDto = AbstractFactory.getInstance().getFormeDao().lister();
                Vector<Forme> listeForme = new Vector<Forme>();
                for (int i = 0; i < listeDto.size(); i++) {
                    listeForme.add(new Forme(listeDto.get(i)));
                }
                return listeForme;
        }
        
        public synchronized static Forme selectId(int idForme) throws RemoteException, FormeInexistantException{
                FormeDto frmDto = AbstractFactory.getInstance().getFormeDao().selectId(idForme);               
                Forme frm = new Forme(frmDto.getIdForme(),frmDto.getLibelleForme()); 
                return frm;
        }
}